package com.yitianyigexiangfa.coad.californium.ues.demo.server;

import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.server.resources.CoapExchange;

/**
 * @author Bill Lau
 * @date 2017-12-06
 */
public class HellWorldServer {

    public static void main(String[] args) {
        CoapServer server = new CoapServer();
        server.add(new TimeResource(), new HelloResource());
        server.start();
    }


    public static class TimeResource extends CoapResource{

        public TimeResource() {
            super("Clock");
            getAttributes().setTitle("Clock");
        }

        @Override
        public void handleGET(CoapExchange exchange) {
            exchange.respond("now is:" + System.currentTimeMillis());
        }
    }

    public static class HelloResource extends CoapResource{

        public HelloResource() {
            super("Hello");
            getAttributes().setTitle("Hello");
        }

        @Override
        public void handleGET(CoapExchange exchange) {
            exchange.respond("Hello World!");
        }
    }

}
